package com.topsun.posclient.finance.view;

import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableLayout;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.ui.part.ViewPart;

import com.topsun.posclient.factory.TuneRepositoryFactory;
import com.topsun.posclient.finance.entity.TuneRepositoryEntity;

public class TuneRepositoryView extends ViewPart{

	public TableViewer tv;

	public static final String ID = "posclient.RepositoryView";
	
	@Override
	public void createPartControl(Composite parent) {
		// TODO Auto-generated method stub
		parent.setSize(500, 500);
		//调用方法创建表格
		createTableViewer(parent);
		//设定内容器
		tv.setContentProvider(new TableViewerContentProvider());
		//设定标签器
		tv.setLabelProvider(new TableViewerLabelProvider());
		//输入数据
		tv.setInput(TuneRepositoryFactory.getRepository());
		addListener();
	}

	private void createTableViewer(Composite parent)
	{	
		tv=new TableViewer(parent,SWT.BORDER|SWT.MULTI|SWT.FULL_SELECTION);
		Table table=tv.getTable();
		table.setHeaderVisible(true);
		table.setLinesVisible(true);
		TableLayout tLayout=new TableLayout();
		table.setLayout(tLayout);
		tLayout.addColumnData(new ColumnWeightData(40));
		new TableColumn(table,SWT.NONE).setText("仓库编码");
		tLayout.addColumnData(new ColumnWeightData(60));
		new TableColumn(table,SWT.NONE).setText("仓库名称");
		tLayout.addColumnData(new ColumnWeightData(60));
		new TableColumn(table,SWT.NONE).setText("上级仓库");
		tLayout.addColumnData(new ColumnWeightData(60));
		new TableColumn(table,SWT.NONE).setText("仓库级次");
		tLayout.addColumnData(new ColumnWeightData(60));
		new TableColumn(table,SWT.NONE).setText("所属部门");
		tLayout.addColumnData(new ColumnWeightData(60));
		new TableColumn(table,SWT.NONE).setText("默认仓管员");
		tLayout.addColumnData(new ColumnWeightData(40));
		new TableColumn(table,SWT.NONE).setText("电话");
		tLayout.addColumnData(new ColumnWeightData(40));
		new TableColumn(table,SWT.NONE).setText("地址");
		tLayout.addColumnData(new ColumnWeightData(40));
		new TableColumn(table,SWT.NONE).setText("备注");
		tLayout.addColumnData(new ColumnWeightData(60));
		new TableColumn(table,SWT.NONE).setText("负库存控");
	}

	public void addListener()
	{
		tv.addDoubleClickListener(new IDoubleClickListener()
		{

			public void doubleClick(DoubleClickEvent event) {
				// TODO 自动生成方法存根
				IStructuredSelection selection=(IStructuredSelection)event.getSelection();
				TuneRepositoryEntity o =(TuneRepositoryEntity)selection.getFirstElement();
				MessageDialog.openInformation(null, "提示", o.getName());
			}
			
		});
		
	}

	@Override
	public void setFocus() {
		// TODO Auto-generated method stub

	}

}
